<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Page System->Error
 * Edit errortable
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2015
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $subpage, $refValidate)
{
	if (isset($_GET['active']))
	{ // mark error as done/not done
		db::getInstance()->where('error_id', $refValidate->cleanslash($_GET['id']));
		$result = db::getInstance()->getOne('error');

		if (db::getInstance()->count <= 0)
			message::setErrorRow(_('Dataerror - Donestatus could not be set!'), TRUE);
		else
		{
			if ($result['error_done'] == '0')
				$data = Array('error_done' => 1);
			else
				$data = Array('error_done' => 0);

			db::getInstance()->where('error_id', $refValidate->cleanslash($_GET['id']));
			db::getInstance()->update('error', $data);
		}

		$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
		if (is_file($pagefile))
			include_once $pagefile;
	}
	else if (isset($_GET['func']))
	{
		if ($refValidate->cleanslash($_GET['func']) === 'edit')
		{ // edit message
			$refPage->assign('scripts',
				'<script type="text/javascript" src="' .
				'module/ckeditor/ckeditor.js"></script>');
			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.editor.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else if (isset($_REQUEST['submit']))
	{
		if ($refValidate->cleanslash($_REQUEST['submit']) === _('Delete'))
		{ // Delete marked Data
			foreach ($_POST['marker'] as $idx)
			{
				$idx = $refValidate->cleanslash($idx);
				db::getInstance()->where('error_id', $idx);
				if (db::getInstance()->delete('error'))
					message::setNoteRow(_('Errormessage succsessful deleted.'), TRUE);
				else
					message::setErrorRow(_('Errormessage could not deleted!'), TRUE);
			}

			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}

		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Cancel'))
		{ // browse measure
			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else
	{ // browse measure
		$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
		if (is_file($pagefile))
			include_once $pagefile;
	}
}

?>